package BinaryTree;
/**
 * 二叉搜索树的最小绝对差
 */
import BinaryTree.init.TreeNode;

public class lc530 {

    TreeNode pre = null;
    Integer result = Integer.MAX_VALUE;
    public int getMinimumDifference(TreeNode root) {
        if (root == null) return 0;
        traversal(root);
        return result;
        
    }
    public void traversal(TreeNode root) {
        if(root==null)return;
        traversal(root.left);
        if (pre != null) {
            result = Math.min(result, Math.abs(pre.val - root.val));
        }
        pre = root;
        traversal(root.right);
    }

}
